﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;

namespace _048.资源冲突问题
{
	internal class StateObject
	{
		// 使用锁
		private Object _lock = new Object();

		private int state = 5;
		public void ChangeState()
		{
			lock (_lock)// 死锁
			{
				if (state == 5)
				{
					state++;// 读写导致的
					Console.WriteLine("State：" + state + "：" + Thread.CurrentThread.ManagedThreadId);
				}
				state = 5;
			}
			
		}
	}
}
